home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 147
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin
/
docs
/
ippon
/
ver
/
013
/
player.c
< prev
Wrap
C/C++ Source or Header
|
2000-07-07
|
4KB
|
176 lines
/* player.c */
#include <sys/iocs.h>
#include <xsp2lib.h>
#include "main.h"
#include "player.h"
#include "shot.h"
#define PLAYER_BANK1 8 /* 少し傾きパターンへ移行するまでの値 */
#define PLAYER_BANK2 12 /* 一番傾きパターンへ以下同文 */
#define PLAYER_SPEED 15 /* 自機の速度 */
#define PLAYER_PALET 0x0700 /* 自機のパレット */
#define PLAYER_START_X 144 /* 自機出現時の座標 */
#define PLAYER_START_Y (256+32)
enum {
PLAYER_PT_RIGHT2 = 0, /* 自機が一番右に傾いている時のパターン */
PLAYER_PT_RIGHT1, /* 〃 少し右に 〃 */
PLAYER_PT_CENTER, /* 〃 正面を向いている時のパターン */
PLAYER_PT_LEFT1, /* 自機が少し右に傾いている時のパターン */
PLAYER_PT_LEFT2 /* 〃 一番右に 〃 */
};
/* ゲーム開始時に呼ばれる */
void PlayerInit (void)
{
}
/* プレイヤー出現時に呼ばれる */
void PlayerAlloc (void)
{
player->lx = PLAYER_START_X * 65536;
player->ly = PLAYER_START_Y * 65536;
player->status = PLAYER_STATUS_APPEAR; /* 出現状態へ */
}
/* 自機が生きている時の移動処理 */
static void PlayerMoveAlive (void)
{
int j; /* ジョイスティックの入力 */
j = _iocs_joyget (0); /* ジョイスティック0番 */
/* [A] ボタンが押されたか? */
if ((j & 0b00100000) == 0)
game_over = !0; /* ゲームオーバーに */
/* [B] ボタンが押されたか? */
if ((j & 0b1000000) == 0)
ShotAlloc ();
/* 自機の上下移動処理 */
switch (j & 0b0011) {
case 0b0010: /* 上 */
player->ly += xytable[PLAYER_SPEED][192].y;
break;
case 0b0001: /* 下 */
player->ly += xytable[PLAYER_SPEED][64].y;
break;
default: /* それ以外 */
break;
}
/* 自機の左右移動処理+左右傾き処理 */
switch (j & 0b1100) {
case 0b1000: /* 左 */
player->lx += xytable[PLAYER_SPEED][128].x;
if (player->bank > 0) {
player->bank = 0;
} else {
if (player->bank > -PLAYER_BANK2)
player->bank--;
}
break;
case 0b0100: /* 右 */
player->lx += xytable[PLAYER_SPEED][0].x;
if (player->bank < 0) {
player->bank = 0;
} else {
if (player->bank < PLAYER_BANK2)
player->bank++;
}
break;
default: /* それ以外 */
/* 自機の傾きを元に戻す処理 */
if (player->bank != 0) {
if (player->bank > 0)
player->bank--;
else
player->bank++;
}
break;
}
/* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
if (player->bank == 0) {
player->pt = obj_player + PLAYER_PT_CENTER;
} else {
if (player->bank > 0) {
if (player->bank < PLAYER_BANK1)
player->pt = obj_player + PLAYER_PT_LEFT1;
else
player->pt = obj_player + PLAYER_PT_LEFT2;
} else {
if (player->bank > -PLAYER_BANK1)
player->pt = obj_player + PLAYER_PT_RIGHT1;
else
player->pt = obj_player + PLAYER_PT_RIGHT2;
}
}
player->x = player->lx / 65536;
player->y = player->ly / 65536;
xobj_set (player->x, player->y, player->pt, PLAYER_PALET | PRIORITY_PLAYER); /* 自機を表示 */
}
/* 自機が死んだ時の移動処理 */
static void PlayerMoveDead (void)
{
/* 座標を初期化 */
player->lx = PLAYER_START_X * 65536;
player->ly = PLAYER_START_Y * 65536;
player->status = PLAYER_STATUS_APPEAR; /* 出現状態へ */
}
/* 自機が死んだ後の登場処理 */
static void PlayerMoveAppear (void)
{
player->bank = 0;
player->pt = obj_player + PLAYER_PT_CENTER;
player->ly -= (4 * 65536);
player->x = player->lx / 65536;
player->y = player->ly / 65536;
/* 自機がある程度上まで進んだら通常状態へ */
if (player->y < 160)
player->status = PLAYER_STATUS_ALIVE;
xobj_set (player->x, player->y, player->pt, PLAYER_PALET | PRIORITY_PLAYER); /* 自機を表示 */
}
/* 垂直同期ごとに呼ばれる */
void PlayerMove (void)
{
switch (player->status) {
case PLAYER_STATUS_ALIVE:
PlayerMoveAlive ();
break;
case PLAYER_STATUS_DEAD:
PlayerMoveDead ();
break;
case PLAYER_STATUS_APPEAR:
PlayerMoveAppear ();
break;
}
}